package com.flyee.communicate.system {

import com.flyee.communicate.Handler;
import com.flyee.io.socket.command.down.CommandDown;
import com.flyee.ro.commanddown.PingDown;
import com.flyee.utils.MyLog;
import com.flyee.utils.Obsevable;

/**
 * Ping 指令处理器.
 * 接受服务器返回ping指令,计算ping并保存ping值
 */
public class PingHandler extends Obsevable implements Handler {
    
    public function PingHandler() {
        //do nothing
        MyLog.debug("init PingHandler");
    }

    public function process(cmd:CommandDown):void {
        var pingCmd:PingDown = cmd as PingDown;
        var ping:Number =  new Date().getTime()-pingCmd.pingTime;
        MyLog.debug("now ping is "+ping);
        //todo 保存当前ping值
        //todo 广播事件,通知界面修改ping值显示
        setChanged();
        
        notifyObsevers("upatePingState",ping);
    }
}
}